通过大熊猫数据帧逐行迭代[duplicate](How to iterate over rows in a DataFrame in Pandas?) 您所在的位置:网站首页 pandas 行迭代 通过大熊猫数据帧逐行迭代[duplicate](How to iterate over rows in a DataFrame in Pandas?)

通过大熊猫数据帧逐行迭代[duplicate](How to iterate over rows in a DataFrame in Pandas?)

#通过大熊猫数据帧逐行迭代[duplicate](How to iterate over rows in a DataFrame in Pandas?)| 来源: 网络整理| 查看: 265

可能重复: 用熊猫循环数据框架最有效的方式是什么?

我正在寻找通过一个大熊猫DataFrame 。 到目前为止,我所做的工作如下:

for i in df.index: do_something(df.ix[i])

有更好的表现和/或更习惯的做法吗? 我知道申请,但有时使用for循环更方便。 提前致谢。

I have a DataFrame from pandas:

import pandas as pd inp = [{'c1':10, 'c2':100}, {'c1':11,'c2':110}, {'c1':12,'c2':120}] df = pd.DataFrame(inp) print df

Output:

c1 c2 0 10 100 1 11 110 2 12 120

Now I want to iterate over the rows of this frame. For every row I want to be able to access its elements (values in cells) by the name of the columns. For example:

for row in df.rows: print row['c1'], row['c2']

Is it possible to do that in pandas?

I found this similar question. But it does not give me the answer I need. For example, it is suggested there to use:

for date, row in df.T.iteritems():

or

for row in df.iterrows():

But I do not understand what the row object is and how I can work with it.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有